#include<iostream>
#include<stdlib.h>
using namespace std;

//作业1：输出常用数据类型占用的字节数
void Misson1(){

    cout<<"int的字节数为："<<sizeof(int)<<endl;
    cout<<"short的字节数为："<<sizeof(short)<<endl;
    cout<<"long的字节数为："<<sizeof(long)<<endl;
    cout<<"char的字节数为："<<sizeof(char)<<endl;
    cout<<"bool的字节数为："<<sizeof(bool)<<endl;
    cout<<"double的字节数为："<<sizeof(double)<<endl;
    cout<<"float的字节数为："<<sizeof(float)<<endl;
}

//作业2：随机生成一个矩阵，输出它的转置矩阵
void Misson2(){
    int row=0; int line=0;
    cout<<"请输入矩阵的行数和列数"<<endl;
    cout<<"行数为：";
    cin>>row;
    cout<<"列数为：";
    cin>>line;
    int a[row][line];
    for(int i=0;i<row;i++){
        for(int j=0;j<line;j++){
            a[i][j]=1+rand()%100;
            cout<<a[i][j]<<"  ";
        }
        cout<<endl;
    }
    cout<<"该矩阵的转置为："<<endl;
    for(int j=0;j<line;j++){
        for(int i=0;i<row;i++){          
            cout<<a[i][j]<<"  ";
        }
        cout<<endl;
    }
}

//拓展1：实现字符串反转
void Misson3(){
    int num=0;
    char a[num];
    cout<<"请输入字符数量"<<endl;
    cin>>num;
    cout<<"请输入字符串"<<endl;
    cin>>a;
    for(int i=num;i>=0;i--){
        char b=a[i-1];
        cout<<b;
    }
    cout<<endl;
}

//拓展2：查找子字符串出现的次数
void Misson4(){
    int nm1=0;int nm2=0;
    int count=0;
    char father[nm1];
    char son[nm2];
    cout<<"请输入长字符串数量"<<endl;
    cin>>nm1;
    cout<<"请输入长字符串"<<endl;
    cin>>father;
    cout<<"请输入短字符数量"<<endl;
    cin>>nm2;
    cout<<"请输入短字符串"<<endl;
    cin>>son;
    for(int i=0; i<nm1; i++){
        int a=i; int b=0;
         while(father[a]==son[b]&&b<nm2&&a<nm1){
            a++;b++;
            if(b==nm2)
            {
            count++;
            }
        }
    }
    cout<<"匹配的次数为："<<count<<endl;
}

int main(){
    Misson1();
    Misson2();
    Misson3();
    Misson4();

    return 0;
}